<template>
	<el-form :model="formData" ref="formRef" :rules="formRules" label-width="10rem">
		<el-row type="flex" :gutter="10">
			<el-col :span="12" v-if="looking!==true">
				<el-form-item label="账号" prop="username">
					<el-input v-model="formData.username"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12" v-if="looking!==true">
				<el-form-item label="密码" prop="password">
					<el-input v-model="formData.password"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="公司名称" prop="work_name">
					<el-input v-model="formData.work_name"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="公司法定代表人姓名" prop="legal_person">
					<el-input v-model="formData.legal_person"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="公司注册地址" prop="register_address">
					<el-input v-model="formData.register_address"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="公司办公地址" prop="work_address">
					<el-input v-model="formData.work_address"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="公司邮政编码" prop="postal_code">
					<el-input v-model="formData.postal_code"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="公司联系电话" prop="work_mobile">
					<el-input v-model="formData.work_mobile"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="公司电子邮箱" prop="work_email">
					<el-input v-model="formData.work_email"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="公司网址" prop="work_site">
					<el-input v-model="formData.work_site"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="联系人姓名" prop="lx_name">
					<el-input v-model="formData.lx_name"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="联系人职务" prop="lx_work">
					<el-input v-model="formData.lx_work"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="联系人办公地址" prop="lx_address">
					<el-input v-model="formData.lx_address"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="联系人联系电话" prop="lx_mobile">
					<el-input v-model="formData.lx_mobile"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="联系人电子邮箱" prop="lx_email">
					<el-input v-model="formData.lx_email"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="公司成立日期" prop="work_time">
					<el-date-picker v-model="formData.work_time" type="date" placeholder="选择日期"></el-date-picker>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="公司性质" prop="work_ment">
					<el-select v-model="formData.work_ment" placeholder="请选择">
						<el-option v-for="item in Companynature" :key="item.value" :label="item.label"
							:value="item.value">
						</el-option>
					</el-select>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="申请入库分类" prop="rk_cate">
					<el-select v-model="formData.rk_cate" placeholder="请选择">
						<el-option v-for="item in catetype" :key="item.id" :label="item.name"
							:value="item.id">
						</el-option>
					</el-select>
					<!-- <el-input v-model="formData.rk_cate"></el-input> -->
				</el-form-item>
			</el-col>

			<el-col :span="12">
				<el-form-item label="公司经营范围" prop="jy_scope">
					<el-input v-model="formData.jy_scope"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="公司资质等级情况" prop="work_level">
					<el-input v-model="formData.work_level"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="公司人数" prop="people_num">
					<el-input v-model="formData.people_num"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="公司占地（办公）面积" prop="area">
					<el-input v-model="formData.area"></el-input>
				</el-form-item>
			</el-col>
			<!-- <el-col :span="12">
				<el-form-item label="是否需要审核" prop="apply_status">
					<el-radio-group v-model="formData.apply_status">
						<el-radio v-for="item in apply_statuslist" :key="item.value" :label="item.value">
							{{item.title}}
						</el-radio>
					</el-radio-group>
				</el-form-item>
			</el-col> -->
		</el-row>
		<el-row type="flex" justify="center">
			<el-button type="primary" icon="el-icon-check" @click="onConfirm">确认</el-button>
			<el-button type="default" icon="el-icon-close" @click="onCancel">取消</el-button>
		</el-row>
	</el-form>
</template>

<script>
	export default {
		name: "supplier-add",
		props:{
			formData: {
				type: Object,
				default: () => {}
			},
			looking:{
				type:Boolean,
				default:()=> null
			},
			catetype: {
				type: Array,
				default: () => []
			},
		},
		data() {
			return {
				Companynature: [{value: 1,label: '国有企业'},{value: 2,label: '私营企业'},{value: 3,label: '外资企业'},
				{value: 4,label: '合资企业'},{value: 5,label: '其他'}], //公司性质
				apply_statuslist:[{value:1,title:'需要审核'},{value:2,title:'不需要审核'}],
				work_time:'',
				formRules: {
					username: [{ required: true,message: '请输入',trigger: 'blur'},
					{min: 6,max: 15,message: "账号长度需6 ~ 15位",trigger: "blur",
					},{pattern: /^(?=.*[a-zA-Z])(?=.*[0-9])[A-Za-z0-9]{8,15}$/,
							message: "账号必须由数字、字母组成、长度在6-15位之间",trigger: "blur",},],
					password: [{ required: true,message: '请输入',trigger: 'blur'},
					{min: 6,max: 32,message: "密码长度需6 ~ 32位",trigger: "blur",
					},{pattern: /^(?=.*[a-zA-Z])(?=.*[0-9])[A-Za-z0-9]{8,15}$/,
							message: "密码必须由数字、字母组成、长度在6-32位之间",trigger: "blur",},],
					work_name: [{ required: true,message: '请输入',trigger: 'blur'}, ],
					work_ment: [{required: true,message: '请选择',trigger: 'change'}],
					legal_person:[{ required: true,message: '请输入',trigger: 'blur'}, ],
					register_address:[{ required: true,message: '请输入',trigger: 'blur'}, ],
					work_address:[{ required: true,message: '请输入',trigger: 'blur'}, ],
					postal_code:[{ required: true,message: '请输入',trigger: 'blur'}, ],
					work_mobile:[{ required: true,message: '请输入',trigger: 'blur'}, ],
					work_email:[
					{ required: true, message: '请输入邮箱地址', trigger: 'blur' },
					{ type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }],
					work_site:[{ required: true,message: '请输入',trigger: 'blur'}, ],
					lx_name:[{ required: true,message: '请输入',trigger: 'blur'}, ],
					lx_work:[{ required: true,message: '请输入',trigger: 'blur'}, ],
					lx_address:[{ required: true,message: '请输入',trigger: 'blur'}, ],
					lx_mobile:[{ required: true,message: '请输入',trigger: 'blur'}, ],
					lx_email:[
					{ required: true, message: '请输入邮箱地址', trigger: 'blur' },
					{ type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }],
					work_time:[{required: true,message: '请选择',trigger: 'change'}],
					rk_cate:[{ required: true,message: '请输入',trigger: 'blur'}, ],
					jy_scope:[{ required: true,message: '请输入',trigger: 'blur'}, ],
					work_level:[{ required: true,message: '请输入',trigger: 'blur'}, ],
					people_num:[{ required: true,message: '请输入',trigger: 'blur'}, ],
					area:[{ required: true,message: '请输入',trigger: 'blur'}, ],
					// apply_status:[{required: true,message: '请选择',trigger: 'change'}],
				}
			};
		},
		methods: {
			onConfirm() {
				if(this.looking){
					this.formData.username = 'admin123'
					this.formData.password = '123456'
					//console.log(this.looking,'looking',this.formData.username,this.formData.password)
				}
				this.$refs.formRef.validate((valid) => {
					if (valid) {
						this.work_time = Math.round(new Date(this.formData.work_time).getTime() / 1000)
						this.formData.work_time = this.work_time
						//console.log(this.formData.work_time,'this.formData.work_time')
						this.$emit("search", this.formData);
						this.$parent.$emit("update:visible", false);
						this.$refs.formRef.resetFields()
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
			onCancel() {
				this.$parent.$emit("update:visible", false);
				this.$refs.formRef.resetFields();
			}
		}
	};
</script>
